package cn.yqx.bankshop.gateway.handler;

import cn.yqx.bankshop.gateway.util.WebfluxResponseUtil;
import org.springframework.http.HttpStatus;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.server.WebFilterExchange;
import org.springframework.security.web.server.authentication.ServerAuthenticationFailureHandler;
import reactor.core.publisher.Mono;

public class CustomServerAuthenticationFailureHandler implements ServerAuthenticationFailureHandler {
    @Override
    public Mono<Void> onAuthenticationFailure(WebFilterExchange webFilterExchange, AuthenticationException e) {
        return WebfluxResponseUtil.responseFailed(webFilterExchange.getExchange(), HttpStatus.FORBIDDEN.value(), e.getMessage());
    }
}
